package com.cloudexpress.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cloudexpress.persistence.dao.UserMapper;
import com.cloudexpress.persistence.model.User;
import com.cloudexpress.persistence.model.UserCriteria;


@Service
public class UserService {

  @Autowired
  private UserMapper userMapper;


  @Transactional
  public void insertUser(User User) {
    userMapper.insert(User);
  }
  
  public User getUserById(int id) {
	  return userMapper.selectByPrimaryKey(id);
  }
  

  public List<User> getUserByEmail(String email) {
	  UserCriteria userExample = new UserCriteria();
	  userExample.createCriteria().andEmailEqualTo(email);
	  List<User> userList = userMapper.selectByExample(userExample);
	  return userList;
  }
  
  public List<User> getUserPagination(int offset, int limit) {
	  List<User> resultList = userMapper.selectByPagination(offset, limit);
	  return resultList;
  }
  
  public void udpateUser(User user) {
	  userMapper.updateByPrimaryKey(user);
  }

}